package com.ml.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author xr-8
 * @date 2021-05-05
 * @time 19:54
 */
@Component
public class Consumer {

    @KafkaListener(topics = "myTopic", groupId = "myGroup")
    public void receiveMessage(ConsumerRecord<String, String> consumerRecord){
        System.out.println("Message start!");
        String topic = consumerRecord.topic();
        String key = consumerRecord.key();
        String value = consumerRecord.value();
        int partition = consumerRecord.partition();
        long timestamp = consumerRecord.timestamp();

        System.out.println("topic:"+topic);
        System.out.println("key:"+key);
        System.out.println("value:"+value);
        System.out.println("partition:"+partition);
        System.out.println("timestamp:"+timestamp);

        System.out.println("Message end!");

    }
}
